#pragma once

#include "../umlmodel_global.h"

#include "../Uml/Element.h"

#include <memory>
using std::shared_ptr;

namespace uml {
class Comment;

/// <summary>
/// ElementRef
/// An ElementRef is a constituent of a model. As such, it has the capability of referencing
/// other Elements.
/// The main intend is to avoid serialize all objects, instead of just save the element id.
/// </summary>
class UMLMODEL_EXPORT ElementRef : public Element {

public: // Constructors and destructors
    explicit ElementRef(const QString& umlType = "uml::ElementRef");

public: // JsonSerializable override
    void fromJson(const QJsonObject& json, QStringList& errorList) override;
    void toJson(QJsonObject& json) override;

public: // Properties
    /// <summary>
    /// The RefID of the element being referenced.
    /// </summary>
    QUuid refId() const { return refId_; }

    void setRefId(const QUuid& refId) { refId_ = refId; }

    /// <summary>
    /// The UML type of the element being referenced.
    /// </summary>
    QString refUmlType() const { return refUmlType_; }

    void setRefUmlType(const QString& refUmlType) { refUmlType_ = refUmlType; }

    /// <summary>
    /// The element being referenced.
    /// </summary>
    shared_ptr<Element> refElement() const { return refElement_; }

    /// <summary>
    /// The element being referenced.
    /// </summary>
    template <typename T> shared_ptr<T> refElementT() const {
        return std::dynamic_pointer_cast<T>(refElement_);
    }

    void setRefElement(shared_ptr<Element> refElement) {
        refElement_ = refElement;
    }

private: // Fields
    /// <summary>
    /// refId
    /// The RefID of the element being referenced.
    /// </summary>
    QUuid refId_ = QUuid();

    /// <summary>
    /// refUmlType
    /// The UML type of the element being referenced.
    /// </summary>
    QString refUmlType_ = "";

    /// <summary>
    /// refElement
    /// The element being referenced.
    /// </summary>
    shared_ptr<Element> refElement_ = nullptr;
};

} // namespace uml
